Page({
  data: {
    lists:'',
    imgUrls:[
      'http://ogm7iyipx.bkt.clouddn.com/3.png',
      'http://ogm7iyipx.bkt.clouddn.com/4.png'
    ],
    indicatorDots: false,
    autoplay: true,
    interval: 2000,
    duration: 1000,
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    this.loadInfo();
    this.loadSwiper();
    this.loadUserInfo();
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  //调用远端服务器API展示首页列表
  loadInfo:function(){
    var page=this;  
    wx.request({
         url:'https://你的域名/API', //访问你服务器的API返回数据
         header:{
             'Content-Type':'application/json'
         },
         success:function(res){
              console.log(res.data);
              page.setData({lists:res.data});
         }
    });
  },
  loadUserInfo(){
    var page = this;
    wx.login({
      success:function(res){
          console.log(res['code']);
          if(res.code){
              //发起网络请求
              wx.request({
                url:'https://你的域名/API', //访问你服务器的API返回数据
                data:{
                  code:res.code
                },
                success:function(res){
                  console.log('--------------');
                  console.log(res);
                  console.log(res.errMsg);
                  console.log(res.statusCode);
                  console.log(res.data);
                  console.log(JSON.parse(res.data));
                  var json = JSON.parse(res.data);
                  console.log(json.openid);
                  page.setData({openid:json.openid});
                }
              })
          }else{
              console.log("获取用户登录态失败！" + res.errMsg);
          }
      }
    }); 
  },
  loadSwiper(){
    var page = this;
    wx.request({
      url:'https://你的域名/API', //访问你服务器的API返回数据
      success: function(res){
        console.log(res.data);
        var imgUrls = res.data;
        page.setData({imgUrls:imgUrls});
      }
    })
  },
  listClick:function(event){
      console.log(event);
      var p = event.currentTarget.id;
      wx.navigateTo({url:'../detail/detail?id='+p});
  },
  changeIndicatorDots: function(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function(e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function(e) {
    this.setData({
      duration: e.detail.value
    })
  },
})